package main

import "fmt"

//0ms 100,1.8MB 80%
func hammingWeight(num uint32) int {
	n := 0
	for num > 0 {
		if num%2 == 1 {
			n++
		}
		num = num / 2
	}
	return n
}

//位运算:0ms 100%,1.8MB 93%
func hammingWeight1(num uint32) int {
	n := 0
	for ; num > 0; num &= num - 1 {
		n++
	}
	return n
}

func main() {
	fmt.Println(hammingWeight(16))
	fmt.Println(hammingWeight1(16))
}
